package com.taotao.springbootApi.service.ServiceImpl;

import com.taotao.springbootApi.entity.User;
import com.taotao.springbootApi.mapper.UserMapper;
import com.taotao.springbootApi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 查询所有
     *
     * @return List<User>
     */
    public List<User> getAll() {
        return userMapper.getAll();
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return user
     */
    public User getById(Integer id) {
        return userMapper.getById(id);
    }

    /**
     * 分页查询
     * 接口路径：/user/page?pageNum=1&pageSize=10
     * limit第一个参数= （pageNum-1)+pageSize
     * 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return List&lt;User&gt;
     */
    @Override
    public List<User> selectPage(Integer pageNum, Integer pageSize, String username) {
        return userMapper.selectPage(pageNum, pageSize,username);
    }

    /**
     * 查询一共有多少条记录
     *
     * @return Integer
     */
    @Override
    public Integer selectTotal(String username) {
        return userMapper.selectTotal(username);
    }


    /**
     * 添加记录
     *
     * @param user
     * @return boolean
     */
    public boolean save(User user) {
        userMapper.save(user);
        return true;
    }

    /**
     * 删除记录
     *
     * @param id
     * @return boolean
     */
    public boolean delete(Integer id) {
        userMapper.delete(id);
        return true;
    }

    /**
     * 更新记录
     *
     * @param user
     * @return boolean
     */
    public boolean update(User user) {
        userMapper.update(user);
        return true;
    }

}
